<?php
namespace Admin\Controller;

class OrderController extends AdminController{

    /**
     * 订单详情
     */
    public function detail(){
        $request['order_sn'] = I('request.order_sn');
        $request['class'] = 'Order';
        $request['method'] = 'orderDetail';
        $ret = callWebInterfaceData($request);
        if(isset($ret['result']['data']['orderInfo']) && $ret['result']['code'] === 0) {
            $data = $ret['result']['data'];
        }
        
        $this->assign($data);
        $this->display();
    }

    /**
     * 统计包片订单数量
     */
    public function count(){

        //关键字筛选
        $keywords = I('request.keywords');
        if($keywords){
            $keywords = '%'.preg_replace('/([_%])/','\\\$1',$keywords).'%';
            $options['where']['host_name'] = ['like',$keywords];
        }

        //时间筛选
        $start_time = I('request.create_time_start') ? strtotime(I('request.create_time_start')) : 0;
        $end_time = I('request.create_time_end') ? strtotime(I('request.create_time_end')) : NOW_TIME;
        $options['where']['order_time'] = ['BETWEEN',[$start_time,$end_time]];
        $options['group'] = 'host_name';
        $options['field'] = 'host_name,COUNT(*) AS `count`';
        $options['where']['video_id'] = ['gt',0];

        //总条数
        $sql = M('CinemaOrder')
            ->where($options['where'])
            ->field($options['field'])
            ->group($options['group'])
            ->buildSql();
        $count = M('CinemaOrder')->table($sql.' AS a')->count();

        //翻页查询
        $pageCount = ceil($count/getPageSize());
        $pageCount = $pageCount ? $pageCount :1;
        $page = I('request.p') > $pageCount ? $pageCount: intval(I('request.p'));
        $page = $page <=0 ? 1 : $page;
        $options['limit'] = ($page-1)*getPageSize().','.getPageSize();
        $list = M('CinemaOrder')->select($options);
        //dump_exit($list);
        $page_title = '包片下单次数统计';

        //页码工具
        $page = new \Think\Page2($count, getPageSize());
        $page = $page->show();
        $this->assign(get_defined_vars());
        $this->display();
    }

}